﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace LUC.Services
{
	public class FontTextBox : UserControl
	{
		private FontDialog fd;
		private Label lb;

		public FontTextBox()
		{
			InitializeComponent();
			SetFont(fd.Font);
		}

		private void InitializeComponent()
		{
			this.lb = new System.Windows.Forms.Label();
			this.fd = new System.Windows.Forms.FontDialog();
			this.SuspendLayout();
			// 
			// lb
			// 
			this.lb.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lb.Location = new System.Drawing.Point(0, 0);
			this.lb.Name = "lb";
			this.lb.Size = new System.Drawing.Size(98, 22);
			this.lb.TabIndex = 0;
			this.lb.Text = "label1";
			this.lb.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.lb.Click += new System.EventHandler(this.lb_Click);
			// 
			// FontTextBox
			// 
			this.BackColor = System.Drawing.SystemColors.ButtonHighlight;
			this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.Controls.Add(this.lb);
			this.Cursor = System.Windows.Forms.Cursors.Hand;
			this.MaximumSize = new System.Drawing.Size(500, 30);
			this.MinimumSize = new System.Drawing.Size(100, 22);
			this.Name = "FontTextBox";
			this.Size = new System.Drawing.Size(98, 22);
			this.Click += new System.EventHandler(this.lb_Click);
			this.ResumeLayout(false);

		}

		public Font CurrentFont
		{
			get
			{
				return fd.Font;
			}
		
			set
			{
				fd.Font = value;
				SetFont(value);
			}

		}

		private void SetFont(Font f)
		{
			lb.Text = Font2String(f);
		}
		
		private void lb_Click(object sender, EventArgs e)
		{
			if (fd.ShowDialog() != DialogResult.OK)
				return;
			SetFont(fd.Font);
		}

		string Font2String(Font f)
		{
			return f.FontFamily.Name + ", " + f.Size.ToString() + ", " + Convert.ToInt32(f.Style).ToString() + ", " +
				Convert.ToInt32(f.Unit).ToString() + ", " + f.GdiCharSet.ToString();
		}
	}
}
